#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int n,k,d[N],ans,in[N],dep[N];

signed main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	n=read(),k=read();
	for(int i=1;i<=n;i++) d[i]=read();	
	ans=(d[1]!=1),d[1]=1;
	for(int i=1;i<=n;i++) in[d[i]]++;
	queue<int> q;
	for(int i=1;i<=n;i++)
		if(!in[i]) q.push(i);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		if(dep[u]==k-1&&d[u]==1) dep[u]=-1;
		else if(dep[u]==k-1){
			dep[u]=-1;
			ans++;
		}
		dep[d[u]]=max(dep[d[u]],dep[u]+1);
		if(!(--in[d[u]])) q.push(d[u]);
	}
	printf("%lld",ans);
	return 0;
}